package org.ichihamigua.video.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.mysql.cj.xdevapi.SchemaImpl;
import org.ichihamigua.common.framework.entity.Result;
import org.ichihamigua.common.video.entity.VideoBulletEntity;
import org.ichihamigua.common.video.entity.VideoEntity;
import org.ichihamigua.common.video.entity.vo.VideoBulletVo;
import org.ichihamigua.video.mapper.VideoBulletMapper;
import org.ichihamigua.video.mapper.VideoMapper;
import org.ichihamigua.video.service.VideoBulletService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @author rainkyzhong
 * @date 2023/10/29 1:29
 */
@Service
public class VideoBulletServiceImpl extends ServiceImpl<VideoBulletMapper, VideoBulletEntity>implements VideoBulletService {
    @Autowired
    private VideoBulletMapper videoBulletMapper;

    @Override
    public Result<?> deleteBullet(Long userId, Long id) {
        LambdaQueryWrapper<VideoBulletEntity> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(VideoBulletEntity::getUserId, userId);
        queryWrapper.eq(VideoBulletEntity::getId, id);
        if(!remove(queryWrapper)) return Result.fail("删除失败");
        return Result.success();
    }

    @Override
    public Result<List<VideoBulletVo>> getBullet(Long videoId) {
        List<VideoBulletEntity> bullets = baseMapper.selectBullet(videoId);
        List<VideoBulletVo> res = new ArrayList<>();
        for (VideoBulletEntity bullet : bullets) {
            res.add(
                    new VideoBulletVo(bullet.getId(),
                        bullet.getContent(),
                        bullet.getAppearTime()
                    )
            );
        }
        return Result.success(res);
    }
}
